home *** CD-ROM | disk | FTP | other *** search
- /* @(#)rename.c 1.2 7/30/90 21:38:48 */
- #ifndef lint
- static char sccs_id[] = "@(#)rename.c 1.2";
- #endif
-
- #include <unistd.h>
-
- rename(old, new)
- char *old, *new;
- {
- /* first make sure there's something to rename */
- if (access(old, F_OK) < 0)
- return(-1);
-
- /* get rid of any existing target file */
- if (access(new, F_OK) == 0)
- unlink(new);
-
- /* link the old to the new */
- if (link(old, new) < 0)
- return(-1);
-
- /* unlink the old name */
- return(unlink(old));
- }
-